const { Client, MessageEmbed, CommandInteraction } = require('discord.js');
const { connection } = require('mongoose');

/**
 * @param {CommandInteraction} interaction
 * @param {Client} client
 */

module.exports = {
  name: 'status',
  description: 'Show status of the client and connection to database',
  async execute(interaction, client) {
    const Response = new MessageEmbed().setColor('PURPLE').setDescription(`
      **Bot Status**\n
      **Client**: *\`🟢 Online\`*
      **Database**: *\`${switchTo(connection.readyState)}\`*\n
      Client ping: *\`${client.ws.ping}ms\`*\n
      **UPTIME**: <t:${parseInt(client.readyTimestamp / 1000)}:R>\n`);

    interaction.reply({ embeds: [Response] });
  },
};

function switchTo(state) {
  let status = '';

  switch (state) {
    case 0:
      status = '🔴 Disconnected';
      break;
    case 1:
      status = '🟢 Connected';
      break;
    case 2:
      status = '🟡 Connecting';
      break;
    case 3:
      status = '🟠 Disonnecting';
      break;
  }

  return status;
}
